package com.qt.collection;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class CollectionDemo01 {
    public static void main(String[] args) {

        Collection<String> coll = new ArrayList<>();
        boolean aaa = coll.add("aaa");
        boolean bbb = coll.add("bbb");
        boolean ccc = coll.add("ccc");
        System.out.println(coll);
        //coll.clear();
        System.out.println("----------------");
        System.out.println(coll);



        System.out.println("--------------");

////        boolean aaa1 = coll.remove("aaa");
//        System.out.println(aaa1);
//
//        boolean aaa2 = coll.contains("aaa");
//        System.out.println(aaa2);

        Iterator<String> it = coll.iterator();

        while (it.hasNext()){
            String next = it.next();
            //String next2 = it.next();
            System.out.println(next);
            //System.out.println(next2);
        }

        //增强for
        for (String s : coll) {
            System.out.println(s);
        }
        //lambda
        coll.forEach(x -> System.out.println(x)

        );

        coll.forEach(s -> System.out.println(s));
        System.out.println("=====================");


        //
        List<String> list1 = new ArrayList<>();
        list1.add("aaa");
        list1.add("bbb");
        list1.add("ccc");
        list1.add(3,"fff");
        System.out.println(list1);
        ArrayList<String> list2 = new ArrayList<>();
        list2.add("aaa");
        list2.add("bbb");
        list2.add("ccc");
        //list2.add(4,"fff");
        // 这里的索引不能大于现有集合的最大索引+1，大一位会自动补再集合的后面，大两位以上会报错；E remove(int   index)

        Iterator<String> iterator = list2.iterator();
        while (iterator.hasNext()){
            iterator.next();
            iterator.remove();

        }

        System.out.println(list2);

        ListIterator<String> listIt = list2.listIterator();
        while (listIt.hasNext()){
            String next = listIt.next();
            listIt.add("我可以新增");
            listIt.remove();
        }

        LinkedList<Object> objects = new LinkedList<>();




    }



}
